
package com.zkmonitor.exception;

public class ShepherException extends Exception {
	private static final long serialVersionUID = 1L;

    private int code;
    private String message;

    private ShepherException(ExceptionEnum exceptionEnum) {
        this(exceptionEnum.getCode(), exceptionEnum.getMessage());
    }

    private ShepherException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ShepherException createIllegalPathException() {
        return new ShepherException(ExceptionEnum.ILLEGALPATH_ERROR);
    }

    public static ShepherException createNoAuthorizationException() {
        return new ShepherException(ExceptionEnum.NOAUTHORIZATION_ERROR);
    }

    

    public static ShepherException createNoSuchUserException() {
        return new ShepherException(ExceptionEnum.NOSUCHUSER_ERROR);
    }

   

    public static ShepherException createNoLoginException() {
        return new ShepherException(ExceptionEnum.NOLOGIN_ERROR);
    }

    public static ShepherException createIllegalParameterException() {
        return new ShepherException(ExceptionEnum.ILLEGAL_PARAMETER_ERROR);
    }

    
    public static ShepherException createIllegalLoginTypeException() {
        return new ShepherException(ExceptionEnum.ILLEGAL_LOGINTYPE_ERROR);

    }

    public static ShepherException createUnknownException() {
        return new ShepherException(ExceptionEnum.UNKNOWN_ERROR);
    }

    
    public static ShepherException createNoNodeException() {
        return new ShepherException(ExceptionEnum.NONODE_ERROR);
    }

    public static ShepherException createNodeExistsException() {
        return new ShepherException(ExceptionEnum.NODEEXISTS_ERROR);
    }

    public static ShepherException createDuplicateKeyException() {
        return new ShepherException(ExceptionEnum.DB_DUPLICATE_KEY);
    }

   

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    private enum ExceptionEnum {
        ILLEGALPATH_ERROR(1001, "Illegal path"),
        NOAUTHORIZATION_ERROR(1002, "No authorization"),
        NOSUCHUSER_ERROR(1003, "No such user"),
        NONODE_ERROR(1004, "No such node"),
        NODEEXISTS_ERROR(1005, "Node already exists"),
        NOLOGIN_ERROR(1006, "Not login"),
        ILLEGAL_PARAMETER_ERROR(1007, "Illegal parameter"),
        ILLEGAL_LOGINTYPE_ERROR(1008, "Illegal login type"),
        DB_DUPLICATE_KEY(1009,"Duplicate key error"),
        UNKNOWN_ERROR(9999, "Internal error");

        private int code;
        private String message;

        ExceptionEnum(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

}
